package com.ccbft.learnfile;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

/**
 * @author Yingyong Lao
 * @date 2021/3/28 21:15
 **/
public class MyFileAdapter extends BaseAdapter {
    private List<MyFile> list;

    public MyFileAdapter(List<MyFile> list) {
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        MyFile myFile = list.get(i);
        view= LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item, viewGroup, false);
        ImageView imageView=view.findViewById(R.id.img);
        TextView textView=view.findViewById(R.id.name);
        if(myFile.getType()==MyFile.FOLDER){//如果是文件夹
            imageView.setImageResource(R.drawable.icons8_folder_96px);
        }else {//如果是文件
            imageView.setImageResource(R.drawable.icons8_file_96px);
        }
        textView.setText(myFile.getName());
        return view;
    }
}
